package com.cykj.pos.mapper;

import com.cykj.pos.domain.BizPosMachineStatusRecords;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cykj.pos.domain.dto.PosMerchantRelatedDTO;
import com.cykj.pos.domain.dto.TransactionDetailsDTO;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 终端设备状态记录Mapper接口
 *
 * @author weijianbo
 * @date 2021-02-02
 */
public interface BizPosMachineStatusRecordsMapper extends BaseMapper<BizPosMachineStatusRecords> {
    /**
     * 生成pos机对应的上层伙伴列表信息 调用mysql的存储过程
     * @param posMerchantRelatedDTO
     * @return
     */
    void generatePosMerchantRelatedProcedure(PosMerchantRelatedDTO posMerchantRelatedDTO);

    /**
     * VUE获取激活设备列表
     * @param bizPosMachineStatusRecords
     * @return
     */
    List<BizPosMachineStatusRecords> list(BizPosMachineStatusRecords bizPosMachineStatusRecords);

    /**
     * VUE查询激活列表已激活状态
     * @param bizPosMachineStatusRecords
     * @return
     */
    List<BizPosMachineStatusRecords> queryListActiv(BizPosMachineStatusRecords bizPosMachineStatusRecords);

    /**
     * pos1.0激活
     * @param snCode
     * @return
     */
    int updatePosOneRecords(String snCode);

    /**
     * 更新激活时间
     * @param acativation
     * @return
     */
    int updateRecordsAcativation(BizPosMachineStatusRecords  bizPosMachineStatusRecords);

    @Select("SELECT records_type FROM biz_pos_machine_status_records WHERE sn_code = #{sn} ")
    String findStatus(String sn);

    void updateRecordsStatus(String snCode);

    void updatePosRecordsStatus(String snCode);

    /**
     * 查询设备激活表
     * @param snCode
     * @return
     */
    BizPosMachineStatusRecords selectBizPosMachineStatusRecordsBysnCode(String snCode);

    /**
     * 存解绑记录
     * @param bizPosMachineStatusRecords
     */
    void insertBizPosRecordsNew(BizPosMachineStatusRecords bizPosMachineStatusRecords);

    /**
     * 删除激活表里的数据
     * @param snCode
     */
    void deleteBizPosRecordsNew(String snCode);

    void deletebizentrySn(String snCode);

    /**
     * 插入激活表数据
     * @param bizPosMachineStatusRecords1
     */
    void insertBizPosMachineStatusRecords(BizPosMachineStatusRecords bizPosMachineStatusRecords1);

    @Update("UPDATE biz_merchant_info set pos_code = '',  whether_binding = '0',whether_photo = '0',whether_video = '0' where pos_code = #{snCode}")
    void updateBizmerchantInfoPosCode(String snCode);
    void updateBizPosRecords(BizPosMachineStatusRecords BizPosMachineStatusRecords);

    @Update("update biz_pos_machine set pos_activate_status=0 where pos_code=#{posSn}")
    void updatePosMachine(String posSn);

    @Select("select sd.dept_name from sys_dept sd left join sys_user su on sd.dept_id=su.dept_id left join biz_merchant bm on su.user_id=bm.user_id left join biz_pos_machine bpm on bm.merch_id=bpm.merch_id where bpm.pos_code=#{posSn}")
    String selectDeptNameByPosCode(String posSn);

    /**
     * 更新激活
     * @param bizPosMachineStatusRecords
     */
    void updateMachineStatusRecordsByXXL(BizPosMachineStatusRecords bizPosMachineStatusRecords);

    int selectActiveCount(TransactionDetailsDTO detailsDTO);

    List<BizPosMachineStatusRecords> selectAllUnActiveRecords();

    List<BizPosMachineStatusRecords> selectAllActiveRecords();
}
